package com.example.myapplication.old.adapter;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.example.myapplication.R;

import java.util.List;

public class JokerAdapter extends RecyclerView.Adapter<JokerAdapter.JokerHolder> {
    private List<String> list;

    public JokerAdapter() {
    }

    public void setData(List<String> list){
        this.list = list;
        notifyDataSetChanged();
    }

    @NonNull
    @Override
    public JokerHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_joker,parent,false);
        return new JokerHolder(view);
    }

    @Override
    public void onBindViewHolder(@NonNull JokerHolder holder, int position) {
        String joker = list.get(position);
        holder.joker_num.setText(position+1+"");
        holder.joker_content.setText(joker);
    }

    @Override
    public int getItemCount() {
        return list == null ? 0 : list.size();
    }

    class JokerHolder extends RecyclerView.ViewHolder {
        TextView joker_num;
        TextView joker_content;
        public JokerHolder(@NonNull View itemView) {
            super(itemView);
            joker_num = itemView.findViewById(R.id.joker_num);
            joker_content = itemView.findViewById(R.id.joker_content);
        }
    }
}
